#!/usr/bin/env python  
# -*- encoding:utf-8 -*-
import wx
import webbrowser, requests
import xingzhengqu
import gaode_single2 as gaode
import threading
import requests, json
import sys, os
import uuid, base64
import mydialog
import code
import hashlib, uuid
import psutil
import mydialog_version

Dic_provice = xingzhengqu.getdic()
# Dic_provice['全国'] = 0
Dic_code = xingzhengqu.getcode()
# Dic_code['全国'] = 0
Dic_cate = xingzhengqu.getdiccate()


def make_onerequests(url):
  while 1:
    try:
      data = requests.get(url, timeout=1)
      return data.text
    except:
      print('error xingzhengqu')


def getshi(adcode_sheng, gaodekey):
  # 输入省的adcode，返回市列表
  url = 'https://restapi.amap.com/v3/config/district?key=%s&keywords=%s' % (
  gaodekey, adcode_sheng)
  data = make_onerequests(url)
  l = json.loads(data)['districts'][0]['districts']
  lshi = [x['name'] for x in l]
  lshicode = [x['adcode'] for x in l]
  dic = {}
  for i in range(len(lshi)):
    dic[lshi[i]] = lshicode[i]
  return lshi, dic


def getdisk():
  # 获取硬盘号
  a = uuid.uuid1()
  a = str(a).split('-')[-1]
  b = a.encode(encoding='utf-8')
  m = hashlib.md5()
  m.update(b)
  str_md5 = m.hexdigest()
  return str_md5


class WorkerThread(threading.Thread):
  def __init__(self, dic, window):
    threading.Thread.__init__(self)
    self.IsBackground = True
    self.dic = dic
    self.window = window
    self.timeToQuit = threading.Event()
    self.timeToQuit.clear()

  def run(self):
    gaode.Gaode(self.dic, self.window)
    sys.exit()


class MyFrame(wx.Frame):

  # def __init__(self,parent,id):
  def __init__(self, parent, id, pos=(500, 500), size=(1300, 600)):
    # wx.Frame.__init__(self,parent,id,'高德POI搜索 V1.0',pos=(500,500),size=(1000,600))
    self.version_now = '2.1.2'
    super(MyFrame, self).__init__(parent, id, title='城市POI查询系统 V{}'.format(
      self.version_now), pos=(500, 500), size=(1300, 600))
    splitter = wx.SplitterWindow(self, -1)
    self.panel = wx.Panel(splitter, -1, size=(100, 100))
    panel2 = wx.Panel(splitter, -1)
    self.panel2 = panel2

    self.getversion()
    self.check_pid()
    self.getkey()
    self.input_pid()

    box_output = wx.BoxSizer(wx.HORIZONTAL)
    self.output = wx.TextCtrl(self.panel2, style=wx.TE_MULTILINE)
    box_output.Add(self.output, 1, wx.EXPAND)
    self.panel2.SetSizerAndFit(box_output)
    panel1 = wx.Panel(splitter, -1)
    splitter.SplitVertically(self.panel, self.panel2, sashPosition=1000)
    self.panel.SetBackgroundColour("White")

    boxall = wx.BoxSizer(wx.HORIZONTAL)
    box1 = wx.BoxSizer(wx.VERTICAL)
    box2 = wx.BoxSizer(wx.VERTICAL)
    box3 = wx.BoxSizer(wx.VERTICAL)
    box4 = wx.BoxSizer(wx.VERTICAL)
    self.makebox1(box1)
    self.makebox2(box2)
    self.makebox3(box3)
    self.makebox4(box4)
    boxall.Add(box1, 0, wx.EXPAND | wx.ALL, 20)
    boxall.Add(box2, 0, wx.EXPAND | wx.ALL, 20)
    boxall.Add(box3, 0, wx.EXPAND | wx.ALL, 20)
    boxall.Add(box4, 0, wx.EXPAND | wx.ALL, 20)

    self.panel.SetSizer(boxall)
    # self.makeMenuBar()
    self.CreateStatusBar()
    self.SetStatusText("")
    self.Centre()

  def getkey(self):
    while 1:
      try:
        url = 'http://129.28.135.123:8005'
        data = requests.get(url)
        data = data.text
        self.gaodekey = data.split('|')
        break
      except:
        print('error code')
        exit()

  def getversion(self):
    while 1:
      try:
        url = 'http://129.28.135.123:8010'
        # data = requests.get(url)
        # data = data.text
        self.version_new = "data"
        break
      except:
        print('error code')
        exit()

  def readpassword(self):
    # 验证是否注册
    return True

  def printmsg(self, msg):
    self.output.AppendText(msg)

  def create_typeloc(self):
    # 方式一 经纬度查询
    boxall = wx.StaticBox(self.panel, -1, '方式一:根据经纬度查询(可选)')
    sizer = wx.StaticBoxSizer(boxall, wx.VERTICAL)

    box = wx.GridBagSizer(hgap=5, vgap=5)

    button = wx.Button(self.panel, -1, "打开GPS查询网站")
    self.Bind(wx.EVT_BUTTON, self.opengps, button)
    box.Add(button, pos=(0, 0), span=(1, 2), flag=wx.EXPAND)

    lstr = ["左上角点经度", "左上角点纬度", "右下角点经度", "右下角点纬度"]
    lloc = ["121.46", "31.30", "121.53", "31.26"]
    lstatic = [wx.StaticText(self.panel, wx.NewId(), x) for x in lstr]
    self.lloc = [wx.TextCtrl(self.panel, wx.NewId(), '') for x in lloc]
    for i in range(4):
      row = i + 1
      box.Add(lstatic[i], pos=(row, 0))
      box.Add(self.lloc[i], pos=(row, 1))
    sizer.Add(box, 1, wx.EXPAND | wx.ALL, 5)
    return sizer

  def create_xingzheng(self):
    # 方式二 行政区查询box
    boxall = wx.StaticBox(self.panel, -1, '方式二:根据行政区查询(必选)')
    sizer = wx.StaticBoxSizer(boxall, wx.VERTICAL)

    box = wx.GridBagSizer(hgap=5, vgap=5)

    self.sampleList = ['无'] + list(Dic_provice.keys())
    self.choice_province = wx.Choice(self.panel, -1, choices=self.sampleList,
                                     name='province')
    size_choice = self.choice_province.GetSize()
    self.choice_shi = wx.Choice(self.panel, -1, size=size_choice, choices=[],
                                name='shi')
    self.choice_xian = wx.Choice(self.panel, -1, size=size_choice, choices=[],
                                 name='xian')
    self.Bind(wx.EVT_CHOICE, self.choose_province, self.choice_province)
    self.Bind(wx.EVT_CHOICE, self.choose_shi, self.choice_shi)
    self.Bind(wx.EVT_CHOICE, self.choose_xian, self.choice_xian)
    text_province = wx.StaticText(self.panel, wx.NewId(), '选择省份')
    text_shi = wx.StaticText(self.panel, wx.NewId(), '选择城市')
    text_xian = wx.StaticText(self.panel, wx.NewId(), '选择区县')
    lchoice = [self.choice_province, self.choice_shi, self.choice_xian]
    ltext = [text_province, text_shi, text_xian]
    for row in range(3):
      box.Add(lchoice[row], pos=(row, 1), flag=wx.EXPAND)
      box.Add(ltext[row], pos=(row, 0), flag=wx.EXPAND)
    sizer.Add(box, 1, wx.EXPAND | wx.ALL, 5)
    return sizer

  def choose_province(self, event):
    # 方式二-设置省份选择框
    self.province = event.GetString()
    if self.province != '无':
      self.out_shengcode = Dic_code[self.province]
      dicshi = Dic_provice[self.province]
      if self.province == '香港特别行政区':
        lshi, self.dic_shi = ['香港特别行政区'], {'香港特别行政区': 810000}
      elif self.province == '澳门特别行政区':
        lshi, self.dic_shi = ['澳门特别行政区'], {'澳门特别行政区': 820000}
      elif self.province == '台湾省':
        lshi, self.dic_shi = ['台湾'], {'台湾': 710000}
      elif self.province == '全国':
        lshi, self.dic_shi = ['全国'], {'全国': 0}
      else:
        lshi, self.dic_shi = getshi(self.out_shengcode, self.gaodekey[0])

      self.choice_shi.Clear()
      self.choice_xian.Clear()
      self.choice_shi.Set(lshi)
    else:
      self.choice_province.Clear()
      self.choice_xian.Clear()
      self.choice_shi.Clear()
      self.choice_province.Set(self.sampleList)

  def choose_shi(self, event):
    # 方式二-设置市选择框
    self.shi = event.GetString()
    self.out_shicode = self.dic_shi[self.shi]
    if self.shi == '台湾':
      lxian, self.dic_xian = ['台湾'], {'台湾': 710000}
    elif self.shi == '全国':
      lxian, self.dic_xian = ['全国'], {'全国': 0}
    else:
      lxian, self.dic_xian = getshi(self.out_shicode, self.gaodekey[0])
    lxian = [x for x in lxian if '市辖区' not in x]
    self.choice_xian.Clear()
    self.choice_xian.Set(lxian)
    if self.province != '全国':
      self.choice_xian.Append('全部区县')

  def choose_xian(self, event):
    # 方式二-设置县区选择框
    self.xian = event.GetString()
    if self.xian == '全部区县':
      self.out_xiancode = 'all'
    else:
      self.out_xiancode = self.dic_xian[self.xian]

  def create_keywords(self):
    # 方式三：根据关键词查询
    boxall = wx.StaticBox(self.panel, -1, '方式三:根据关键词查询(可选)')
    sizer = wx.StaticBoxSizer(boxall, wx.VERTICAL)

    text = wx.StaticText(self.panel, wx.NewId(), '请输入关键词（以空格分隔）')
    self.keywords = wx.TextCtrl(self.panel, wx.NewId(), value='',
                                style=wx.TE_MULTILINE)
    sizer.Add(text, 0, wx.LEFT, 5)
    sizer.Add(self.keywords, 1, wx.EXPAND | wx.ALL, 5)  # 1代表主方向改变
    return sizer

  def makebox1(self, box1):
    # 第一步 选择查询方式页面
    s = wx.StaticText(self.panel, -1, "第一步 选择查询方式", style=wx.ALIGN_CENTER)
    self.bold(s)
    box1.Add(s, 0, wx.EXPAND)  # 0表示在主方向不改变，剩下的三个box按照1:1:1分空间
    box1_1 = self.create_typeloc()
    box1_2 = self.create_xingzheng()
    box1_3 = self.create_keywords()
    flagsExpand = wx.SizerFlags(1)
    flagsExpand.Expand().Border(wx.ALL, 10)
    box1.Add(box1_1, 1, wx.EXPAND | wx.ALL, 10)
    box1.Add(box1_2, 1, wx.EXPAND | wx.ALL, 10)
    box1.Add(box1_3, 1, wx.EXPAND | wx.ALL, 10)

  def makebox2(self, box2):
    # 第二步 选择输出的POI类别
    flagsExpand = wx.SizerFlags(1)
    flagsExpand.Expand().Border(wx.ALL, 15)
    title = wx.StaticText(self.panel, -1, "第二步 选择输出的POI类别",
                          style=wx.ALIGN_CENTER)
    self.bold(title)
    box2.Add(title, 0, wx.BOTTOM, 5)
    lname = ['汽车服务', '汽车销售', '汽车维修', '摩托车服务', '餐饮服务', '购物服务', '生活服务', '体育休闲服务',
             '医疗保健服务', '住宿服务', '风景名胜', '商务住宅', '政府机构及社会团体', '科教文化服务', '交通设施服务',
             '金融保险服务', '公司企业', '道路附属设施', '地名地址信息', '公共设施', '事件活动', '室内设施',
             '通行设施', '以上全选']
    self.listbox = wx.CheckListBox(parent=self.panel, id=-1, choices=lname)
    self.checkall = False
    self.Bind(wx.EVT_CHECKLISTBOX, self.Onlistbox, self.listbox)
    box2.Add(self.listbox, 1, wx.EXPAND | wx.ALL, 5)

  def Onlistbox(self, event):
    if self.listbox.IsChecked(23) and not self.checkall:
      self.checkall = True
      for i in range(24):
        self.listbox.Check(i, check=True)
    if self.checkall and len(self.listbox.GetCheckedItems()) != 24:
      self.listbox.Check(23, check=False)
      self.checkall = False
    if not self.listbox.IsChecked(23) and len(
        self.listbox.GetCheckedItems()) == 23:
      for i in range(23):
        self.listbox.Check(i, check=False)

  def makebox3(self, box3):
    flagsExpand = wx.SizerFlags(1)
    flagsExpand.Expand().Border(wx.ALL, 15)
    title = wx.StaticText(self.panel, -1, "第三步 选择输出POI的字段",
                          style=wx.ALIGN_CENTER)
    self.bold(title)
    box3.Add(title, 0, wx.BOTTOM, 5)
    lname = ['唯一ID', 'POI名称', 'POI类型', 'POI类型编号', '行业类型', '地址', '经度', '纬度',
             'POI所在省份名称', 'POI所在城市名称', '区域编码', '商家电话', '店铺评分', '人均消费', '以上全选']
    self.listbox2 = wx.CheckListBox(parent=self.panel, id=-1, choices=lname)
    self.checkall2 = False
    self.Bind(wx.EVT_CHECKLISTBOX, self.Onlistbox2, self.listbox2)
    box3.Add(self.listbox2, 1, wx.EXPAND | wx.ALL, 5)

  def Onlistbox2(self, event):
    if self.listbox2.IsChecked(14) and not self.checkall2:
      # 选择了全选，勾选所有的选项
      self.checkall2 = True
      for i in range(15):
        self.listbox2.Check(i, check=True)
    if self.checkall2 and len(self.listbox2.GetCheckedItems()) != 15:
      self.listbox2.Check(14, check=False)
      self.checkall2 = False
    if not self.listbox2.IsChecked(14) and len(
        self.listbox2.GetCheckedItems()) == 14:
      for i in range(14):
        self.listbox2.Check(i, check=False)

  def makebox4(self, box4):
    # 第三步 设置输出参数
    s = wx.StaticText(self.panel, -1, "第四步 设置输出参数", style=wx.ALIGN_CENTER)
    self.bold(s)
    box4.Add(s, 0, wx.BOTTOM, 5)
    sampleList = ['csv', 'txt']
    self.radio = wx.RadioBox(self.panel, id=-1, label='请选择输出文件格式',
                             choices=sampleList)
    box4.Add(self.radio, 1, wx.EXPAND)
    # self.cpu = wx.SpinCtrl(self.panel, -1, "")
    # self.cpu.SetRange(5,30)
    # self.cpu.SetValue(5)
    box_cpu = wx.BoxSizer(wx.VERTICAL)
    lsudu = ['速度优先', '数量优先']
    self.sudu = wx.RadioBox(self.panel, id=-1, label="请选择关键词搜索模式",
                            choices=lsudu)
    box_cpu.Add(self.sudu, 1, wx.EXPAND)
    flagsExpand = wx.SizerFlags(1)
    flagsExpand.Expand().Border(wx.ALL, 10)
    box4.Add(box_cpu, flagsExpand)

    button_path = wx.Button(self.panel, -1, "选择保存位置并输入文件名")
    button_cal = wx.Button(self.panel, -1, "开始搜索")
    button_exit = wx.Button(self.panel, -1, "退出")
    if self.version_now == self.version_new:
      button_version = wx.Button(self.panel, -1, "当前为最新版本")
    else:
      button_version = wx.Button(self.panel, -1, "点击更新版本")
    if self.readpassword():
      button_password = wx.Button(self.panel, -1, "已注册")
    else:
      button_password = wx.Button(self.panel, -1, "点击注册")
    box4.Add(button_path, 1, wx.EXPAND | wx.TOP, 5)
    box4.Add(button_password, 1, wx.EXPAND | wx.TOP, 5)
    box4.Add(button_cal, 1, wx.EXPAND | wx.TOP, 5)
    box4.Add(button_exit, 1, wx.EXPAND | wx.TOP, 5)
    box4.Add(button_version, 1, wx.EXPAND | wx.TOP, 5)

    self.Bind(wx.EVT_BUTTON, self.choosepath, button_path)
    self.Bind(wx.EVT_BUTTON, self.cal, button_cal)
    self.Bind(wx.EVT_BUTTON, self.register, button_password)
    self.Bind(wx.EVT_BUTTON, self.OnExit, button_exit)

    if self.version_now != self.version_new:
      self.Bind(wx.EVT_BUTTON, self.openyunpan, button_version)

  def register(self, event):
    # 用户注册
    if self.readpassword():
      # 无需注册
      self.output.AppendText('您已注册\n')
    else:
      # 需要注册
      dialog = mydialog.Register(self)
      result = dialog.ShowModal()

  def makeMenuBar(self):
    fileMenu = wx.Menu()
    helloItem = fileMenu.Append(-1, "&Hello...\tCtrl-H",
                                "Help string shown in status bar for this menu item")
    fileMenu.AppendSeparator()
    exitItem = fileMenu.Append(wx.ID_EXIT)
    helpMenu = wx.Menu()
    aboutItem = helpMenu.Append(wx.ID_ABOUT)
    menuBar = wx.MenuBar()
    menuBar.Append(fileMenu, "&File")
    menuBar.Append(helpMenu, "&Help")
    self.SetMenuBar(menuBar)

    # Finally, associate a handler function with the EVT_MENU event for
    # each of the menu items. That means that when that menu item is
    # activated then the associated handler function will be called.
    self.Bind(wx.EVT_MENU, self.OnHello, helloItem)
    self.Bind(wx.EVT_MENU, self.OnExit, exitItem)
    self.Bind(wx.EVT_MENU, self.OnAbout, aboutItem)

  def OnExit(self, event):
    """Close the frame, terminating the application."""
    self.Close(True)

  def OnHello(self, event):
    """Say hello to the user."""
    wx.MessageBox("Hello again from wxPython")

  def OnAbout(self, event):
    """Display an About Dialog"""
    wx.MessageBox("This is a wxPython Hello World sample",
                  "About Hello World 2",
                  wx.OK | wx.ICON_INFORMATION)

  def bold(self, s):
    font = s.GetFont()
    font.PointSize += 2
    font = font.Bold()
    s.SetFont(font)

  def opengps(self, event):
    url = 'http://www.gpsspg.com/maps.htm'
    webbrowser.open(url)

  def openyunpan(self, event):
    while 1:
      try:
        url = 'http://129.28.135.123:8020'
        data = requests.get(url)
        data = data.text
        urlyunpan = data
        break
      except:
        print('error code')
        exit()
    webbrowser.open(urlyunpan)

  def choosepath(self, event):
    wildcard = ''
    with wx.FileDialog(self, "选择输出文件路径", wildcard=wildcard,
                       style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) as fileDialog:
      if fileDialog.ShowModal() == wx.ID_CANCEL:
        return  # the user changed their mind
      # save the current contents in the file
      self.path = fileDialog.GetPath()
      print(self.path, 111)

  def getxingzheng(self, choice):
    # 获取用户选择的行政区
    name = choice.GetString(choice.GetSelection())
    if name != '' and name != '全部区县':
      code = Dic_code[name]
    elif name != '' and name == '全部区县':
      code, name = 'null', 'null'
    else:
      code, name = 'null', 'null'
    return name, code

  def getcate(self):
    # 获取用户选择的类别
    lcate = self.listbox.GetCheckedStrings()
    if len(lcate) == 0:
      return 'error', 'error'
    if '以上全选' in lcate:
      lcatecode = list(Dic_cate.values())
    else:
      lcatecode = [Dic_cate[x] for x in lcate]
    return lcate, lcatecode

  def getcateout(self):
    # 获取用户选择的输出类别
    lcate = self.listbox2.GetCheckedStrings()
    lcate = [x for x in lcate if x != '以上全选']
    # print(lcate)
    if len(lcate) == 0:
      return 'error'
    return list(lcate)

  def getpath(self):
    # 获取用户选择的输出路径
    if hasattr(self, 'path'):
      if '.csv' not in self.path and '.txt' not in self.path and '.shp' not in self.path:
        self.path = self.path + '.%s' % self.radio.GetString(
          self.radio.GetSelection())
      self.path.replace('\\\\', '\\')
      self.path.replace(':\\', ':\\\\')
      return self.path
    else:
      return 'error'

  def getlloc(self):
    # 获取用户输入的经纬度
    l = [x.GetLineText(0) for x in self.lloc]
    l_notnull = [x for x in l if len(x) != 0]
    if len(l_notnull) == 0:
      return 'null'
    else:
      try:
        x1, y1, x2, y2 = [round(float(x), 2) for x in l_notnull]
        if 0 < x1 < x2 < 180 and 180 > y1 > y2 > 0:
          return l
        else:
          return 'error'
      except:
        return 'error'

  def getkeywords(self):
    # 获取用户输入的关键词
    keywords = self.keywords.GetLineText(0)
    if keywords == '':
      return 'null'
    else:
      return keywords

  def getdata(self):
    # 读取用户输入的参数
    c_province = self.choice_province
    c_shi = self.choice_shi
    c_xian = self.choice_xian
    self.out_province = c_province.GetString(c_province.GetSelection())
    self.out_shi = c_shi.GetString(c_shi.GetSelection())
    self.out_xian = c_xian.GetString(c_xian.GetSelection())

    self.out_lloc = self.getlloc()
    self.out_path = self.getpath()
    self.out_cate, self.out_catecode = self.getcate()
    self.out_keywords = self.getkeywords()
    self.out_type = self.radio.GetString(self.radio.GetSelection())
    self.out_key = self.getkey()
    self.out_cateout = self.getcateout()

  def input_pid(self):
    pid = os.getpid()
    while 1:
      try:
        url = 'http://129.28.135.123:8006?key=%s&pid=%s' % (getdisk(), pid)
        data = requests.get(url)
        data = data.text
        break
      except:
        print('error code')
        exit()

  def check_pid(self):
    lpidnow = psutil.pids()
    lpidnow = [str(x) for x in lpidnow]
    while 1:
      try:
        url = 'http://129.28.135.123:8007?key=%s' % (getdisk())
        data = requests.get(url)
        data = data.text
        if data == 'null':
          lpid = 'null'
        else:
          lpid = data.split('|')
          break
      except:
        print('error code')
        exit()
    lpid = [x.replace('.0', '') for x in lpid]
    if lpid != 'null':
      for pid in lpid:
        if pid in lpidnow:
          exit()

  def cal(self, event):
    self.getdata()
    lcheck = [self.out_lloc, self.out_keywords,
              self.out_province, self.out_xian, self.out_shi]
    lcheck = [x for x in lcheck if x != 'null']
    if self.out_path != 'error':  # 保证用户必须输入输出路径
      if self.out_cate != 'error':  # 保证用户必须输入类别
        if self.out_lloc != 'error':  # 保证用户不输入错误的经纬度
          if len(lcheck) != 0:  # 保证用户至少输入方式一中的一个参数
            if self.out_cateout != 'error':
              if self.out_key != 'error':
                if self.out_province != '':
                  if self.out_shi != '':
                    if self.out_xian != '':
                      if self.readpassword():
                        if not (
                            self.province == '全国' and self.out_keywords == 'null'):
                          l1 = [self.out_lloc, self.out_province,
                                self.out_xian, self.out_shi, self.out_keywords]
                          l3 = [self.out_type, self.out_key]
                          dialog = mydialog.SubclassDialog(l1, self.out_cate,
                                                           l3)
                          result = dialog.ShowModal()
                          dic = self.builddic()
                          # print(dic)
                          # print(result)
                          if result == 5100:
                            thread = WorkerThread(dic, self)
                            thread.start()
                        # gaode.Gaode(dic, self.output)
                        else:
                          wx.LogError("全国搜索时必须输入关键词")
                      else:
                        wx.LogError("请注册")
                    else:
                      wx.LogError("请选择行政区(区县)")
                  else:
                    wx.LogError("请选择行政区(市)")
                else:
                  wx.LogError("请选择行政区(省)")
              else:
                wx.LogError("您输入的key不正确")
            else:
              wx.LogError("请至少选择一个输出字段")
          else:
            wx.LogError("请至少选择一个查询方式")
        else:
          wx.LogError("请输入正确的经纬度")
      else:
        wx.LogError("您未选择POI类别")
    else:
      wx.LogError("您未选择输出文件路径")

  def builddic(self):
    # 将用户输入的参数打包为字典传递给高德类
    dic = {
      'lloc': self.out_lloc, 'province': self.province,
      'shi': self.out_shicode, 'keywords': self.out_keywords,
      'xian': self.out_xiancode, 'cate': self.out_catecode,
      'type': self.out_type, 'key': self.out_key, 'path': self.out_path,
      'cateout': self.out_cateout,
      'sudu': self.sudu.GetString(self.sudu.GetSelection()),
      'gaodekey': self.gaodekey
    }
    return dic


if __name__ == '__main__':
  app = wx.App()
  myframe = MyFrame(parent=None, id=-1)
  myframe.Show(True)
  app.MainLoop()